package dissertation.common.utils.applicationxml.factory;

import dissertation.common.utils.applicationxml.builder.ApplicationXMLBuilderV30;
import dissertation.common.utils.applicationxml.builder.ApplicationXMLBuilderV31;
import dissertation.common.utils.applicationxml.builder.IApplicationXMLBuilder;
import static dissertation.common.constants.Constants.*;

/**
 * Application XML Builder Factory class
 */
public class ApplicationXMLBuilderFactory {
    private static ApplicationXMLBuilderFactory instance;

    /**
     * Builder factory method
     * @param version - ejb version
     * @return - the builder instance
     */
    public IApplicationXMLBuilder getBuilder(String version) {
        IApplicationXMLBuilder result = null;
        if (EJB_VERSION_3_0.equals(version)) {
            result = new ApplicationXMLBuilderV30();
        } else if (EJB_VERSION_3_1.equals(version)) {
            result = new ApplicationXMLBuilderV31();
        }

        return result;
    }

    /**
     * Singleton instance retrieval method
     * @return - an instance
     */
    public synchronized static ApplicationXMLBuilderFactory getInstance() {
        if (instance == null) {
            instance = new ApplicationXMLBuilderFactory();
        }

        return instance;
    }
}
